package leetcode.editor.vscdev.hot100;
import leetcode.editor.utils.*;

public class lc26_deleteDuplicates {

}

class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode dummy = new ListNode();
        dummy.next = head;
        ListNode cur = dummy;
        while (cur.next != null && cur.next.next != null) {
            if (cur.next.val == cur.next.next.val) {
                int val = cur.next.val; // 重复的值
                while (cur.next != null && cur.next.val == val) {
                    cur.next = cur.next.next; // 所有重复的元素通通杀掉
                }
            } else {
                cur = cur.next;
            }
        }
        return dummy.next;
    }
}